package com.ns.core.current;

import com.ns.core.utils.date.CalendarPattern;
import com.ns.core.utils.date.CalenderUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.net.InetAddress;

/**
 * spring boot启动之后
 *
 * @author lw
 */
@Component
public class InitStartup implements CommandLineRunner {
    private final static Logger LOGGER = LoggerFactory.getLogger(InitStartup.class);

    @Value("${spring.application.name:e-soha}")
    private String applicationName;

    @Value("${server.port:8080}")
    private String port;

    @Value("${server.servlet.context-path:}")
    private String path;

    @Value("${spring.profiles.active:}")
    private String active;

    @Override
    public void run(String... args) throws Exception {
        try {
            String ip = InetAddress.getLocalHost().getHostAddress();
            String str = "\n------------- " + applicationName + " (" + active + ") 启动成功 -- BY " + CalenderUtil.getNowString(CalendarPattern.ALL_YMD_HMS) + " -------------\n" +
                    "\t- Local2:  http://127.0.0.1:" + port + path + "";
            LOGGER.info(str + "\t- Network: http://" + ip + ":" + port + path + "\n");
        } catch (Exception e) {
            LOGGER.info("\t- Network: 未能成功获取\n异常：" + e.getMessage());
        }
    }
}

